<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "mall_appear".
 *
 * @property int $id
 * @property int $openid 用户openid
 * @property int $uid 提现用户的id
 * @property string $amount 金额
 * @property int $status 1提现中|审核中 2提现成功 3提现失败
 * @property string $reason 拒绝理由
 * @property int $create_time 创建时间
 * @property int $finish_time 完成时间
 * @property int $check_id 操作者id
 * @property int $mid 商家id
 */
class MallAppear extends \yii\db\ActiveRecord
{

    public $create_time_start;

    public $create_time_end;
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'mall_appear';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['openid', 'amount', 'create_time'], 'required'],
            [['uid', 'status', 'create_time', 'finish_time', 'check_id', 'mid'], 'integer'],
            [['amount'], 'number'],
            [['reason'], 'string', 'max' => 50],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'mid' => '商家id',
            'openid' => 'Openid',
            'uid' => '用户ID',
            'amount' => '金额',
            'status' => '状态',
            'reason' => '理由',
            'create_time' => '发起时间',
            'finish_time' => '完成时间',
            'check_id' => '操作账号',
            'create_time_start' => '发起开始时间',
            'create_time_end' => '发起结束时间',
        ];
    }

    /**
     * 关联用户表
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(EduUser::class, ['openid' => 'openid']);
    }

    public static function attributeValue()
    {
        return [
            'status' => [
                '' => '',
                '1' => '提现中',
                '2' => '提现成功',
                '3' => '提现失败',
            ],
        ];
    }

    public function getStatusValue()
    {
        switch ($this->status)
        {
            case 1:
                $value = '提现中';
                break;
            case 2:
                $value = '提现成功';
                break;
            case 3:
                $value = '提现失败';
                break;
            default:
                $value = '其他';
                break;
        }
        return $value;
    }

}
